package cn.wd.service.impl;


import cn.wd.domain.LoginLog;
import cn.wd.mapper.LoginLogMapper;
import cn.wd.page.PageResult;
import cn.wd.qo.QueryObject;
import cn.wd.service.ILoginLogService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class LoginLogServiceImpl implements ILoginLogService {

    private final LoginLogMapper mapper;

    public LoginLogServiceImpl(LoginLogMapper mapper) {
        this.mapper = mapper;
    }


    @Override
    public PageResult<LoginLog> query(QueryObject qo) {
        long total = mapper.selectForCount(qo);
        if (total == 0) {
            return PageResult.empty(qo.getCurrentPage(), qo.getPageSize());
        }
        List<LoginLog> loginLogs = mapper.selectForList(qo);
        return new PageResult<>(qo.getCurrentPage(), qo.getPageSize(), total, loginLogs);
    }

    @Override
    public void save(LoginLog obj) {
        mapper.insert(obj);
    }

    @Override
    public void updateById(LoginLog obj) {
        mapper.updateByPrimaryKey(obj);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public LoginLog selectById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<LoginLog> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public void batchDelete(Long[] deletedIds) {
        mapper.batchDelete(deletedIds);
    }
}
